<?php
	/* Functions in this file */
	/**************************/

	// GetMFCClassName()
	// GetMFCClassSchema()
	// GetPosition()
	// GetRhythmSlashVolume()
	// GetStaff()
	// GetStaffVolume()
	// GetSystem()
	// GetText($rhythmSlashes)
	// GetVolume($rhythmSlashes)
	// IsRhythmSlashVolumeSet()
	// IsStaffVolumeSet()
	// IsValidPosition($position)
	// IsValidStaff($staff)
	// IsValidSystem($system)
	// IsValidVolume($volume)
	// IsVolumeSet($rhythmSlashes)
	// SetPosition($position)
	// SetRhythmSlashVolume($volume)
	// SetStaff($staff)
	// SetStaffVolume($volume)
	// SetSystem($system)
?>
<?php
	 
	 
	 
	 
	class Dynamic {
		 
		 
		// Constants
		// Default constants
		const DEFAULT_SYSTEM = 0;
		const DEFAULT_STAFF = 0;
		const DEFAULT_POSITION = 0;
		const DEFAULT_DATA = 0x00006800;
		const DEFAULT_STAFF_VOLUME = self::fff;
		const DEFAULT_RHYTHM_SLASH_VOLUME = 0;
		 
		// System Constants
		const MIN_SYSTEM = 0;
		const MAX_SYSTEM = 65535;
		 
		// Staff Constants
		const MIN_STAFF = 0;
		const MAX_STAFF = 2;
		 
		// Position Constants
		const MIN_POSITION = 0;
		const MAX_POSITION = 255;
		// Volume constants
		 
		const notSet = 0x000000ff;
		const fff = 104;
		const ff = 91;
		const f = 78;
		const mf = 65;
		const mp = 52;
		const p = 39;
		const pp = 26;
		const ppp = 13;
		const off = 0;
		 
		 
		 
		protected $m_system = self::DEFAULT_SYSTEM;
		protected $m_staff = self::DEFAULT_STAFF;
		protected $m_position = self::DEFAULT_POSITION;
		protected $m_data = self::DEFAULT_DATA;
		 
		 
		 
		 
		function GetMFCClassName() {
			return "CDynamic";
		}
		 
		 
		function GetMFCClassSchema() {
			return 1;
		}
		 
		// System Functions
		 
		 
		 
		function IsValidSystem($system) {
			return (($system >= self::MIN_SYSTEM) && ($system <= self::MAX_SYSTEM));
		}
		 
		 
		 
		function SetSystem($system) {
			if (!$this->IsValidSystem($system)) return 0;
			$this->m_system = $system;
			return 1;
		}
		 
		 
		function GetSystem() {
			return ($this->m_system);
		}
		 
		// Staff Functions
		 
		 
		 
		function IsValidStaff($staff) {
			return (($staff >= self::MIN_STAFF) && ($staff <= self::MAX_STAFF));
		}
		 
		 
		 
		function SetStaff($staff) {
			if (!$this->IsValidStaff($staff)) return 0;
			$this->m_staff = $staff;
			return 1;
		}
		 
		 
		function GetStaff() {
			return ($this->m_staff);
		}
		 
		// Position Functions
		 
		 
		 
		function IsValidPosition($position) {
			return (($position >= self::MIN_POSITION) && ($position <= self::MAX_POSITION));
		}
		 
		 
		 
		function SetPosition($position) {
			if (!$this->IsValidPosition($position)) return 0;
			$this->m_position = $position;
			return 1;
		}
		 
		 
		function GetPosition() {
			return ($this->m_position);
		}
		 
		// Volume Functions
		 
		 
		 
		function IsValidVolume($volume) {
			return (($volume == self::notSet) || ($volume == self::fff) || ($volume == self::ff) || ($volume == self::f) || ($volume == self::mf) || ($volume == self::mp) || ($volume == self::p) || ($volume == self::pp) || ($volume == self::ppp) || ($volume == self::off));
		}
		// Staff Volume Functions
		 
		 
		 
		function SetStaffVolume($volume) {
			return $this->SetVolume(0, $volume);
		}
		 
		 
		function GetStaffVolume() {
			return $this->GetVolume(0);
		}
		 
		 
		function IsStaffVolumeSet() {
			return $this->IsVolumeSet(0);
		}
		 
		// Rhythm Slash Functions
		function SetRhythmSlashVolume($volume) {
			return $this->SetVolume(1, $volume);
		}
		 
		 
		function GetRhythmSlashVolume() {
			return $this->GetVolume(1);
		}
		 
		 
		function IsRhythmSlashVolumeSet() {
			return $this->IsVolumeSet(1);
		}
		 
		 
		// Constructor/Destructor
		 
		 
		function Dynamic($system = NULL, $staff = NULL, $position = NULL, $staffVolume = NULL, $rhythmSlashVolume = NULL) {
		 
			if (!$this->IsValidSystem($system)) return 0;
			if (!$this->IsValidStaff($staff)) return 0;
			if (!$this->IsValidPosition($position)) return 0;
			$this->SetSystem($system);
			$this->SetStaff($staff);
			$this->SetPosition($position);
			$this->SetStaffVolume($staffVolume);
			$this->SetRhythmSlashVolume($rhythmSlashVolume);
		}
		 
		 
		function DoSerialize(&$stream) {
		 
		
			WRITE_WORD ($stream,$this->m_system);
			WRITE_BYTE ($stream,$this->m_staff);
			WRITE_BYTE ($stream,$this->m_position);
			WRITE_WORD ($stream,$this->m_data);

			return 1;
		}
		 
		
		 
		 
		 
		function DoDeserialize(&$stream) {
		 
			$this->m_system = READ_WORD ($stream);
			$this->m_staff = READ_BYTE ($stream);
			$this->m_position = READ_BYTE ($stream);
			$this->m_data = READ_WORD ($stream);
		}
		 
		// Volume Functions
		
		 
		 
		 
		function SetVolume($rhythmSlashes, $volume) {
			 
			//------Last Checked------//
			// - Jan 12, 2005
			if (!$this->IsValidVolume($volume)) return 0;
			 
			if ($rhythmSlashes)
				$this->m_data = MAKEWORD($volume, $this->GetStaffVolume());
			else
				$this->m_data = MAKEWORD($this->GetRhythmSlashVolume(), $volume);
			 
			return 1;
		}
		 
		 
		 
		 
		function GetVolume($rhythmSlashes) {
			 
			//------Last Checked------//
			// - Jan 12, 2005
			if ($rhythmSlashes)
				return (LOBYTE($this->m_data));
			return (HIBYTE($this->m_data));
		}
		 
		 
		 
		 
		function IsVolumeSet($rhythmSlashes) {
			 
			//------Last Checked------//
			// - Jan 13, 2005
			$volume = (($rhythmSlashes) ? $this->GetRhythmSlashVolume() : $this->GetStaffVolume());
			return ($volume != self::notSet);
		}
		 
		// Operations
		 
		 
		 
		function GetText($rhythmSlashes) {
			 
			//------Last Checked------//
			// - Jan 13, 2005
			// Get the appropriate $volume level
			$volume = $this->GetVolume($rhythmSlashes);
			 
			if ($volume == self::off)
				return "off";
			else if ($volume <= self::ppp)
			return "ppp";
			else if ($volume <= self::pp)
			return "pp";
			else if ($volume <= self::p)
			return "p";
			else if ($volume <= self::mp)
			return "mp";
			else if ($volume <= self::mf)
			return "mf";
			else if ($volume <= self::f)
			return "f";
			else if ($volume <= self::ff)
			return "ff";
			 
			return "fff";
		}
		 
		 
	}
	 
?>


